<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta http-equiv="Expires" CONTENT="0">
        <meta http-equiv="Cache-Control" CONTENT="no-cache">
        <meta http-equiv="Pragma" CONTENT="no-cache">
        <title>CookieShop</title>
        <link rel="stylesheet" type="text/css" href="../easyui/themes/default/easyui.css">
        <link rel="stylesheet" type="text/css" href="../easyui/themes/icon.css">
        <link rel="stylesheet" type="text/css" href="../easyui/demo/demo.css">
        <!--  link rel="stylesheet" type="text/css" href="../qunit/qunit-1.20.0.css">-->
        <script type="text/javascript" src="../easyui/jquery.min.js"></script>
        <script type="text/javascript" src="../easyui/jquery.easyui.min.js"></script>
        <script type="text/javascript" src="../js/sha1.js"></script>
    </head>
    <body style="background:#B3DFDA;">
        <!--  div id="qunit"></div>
        <div id="qunit-fixture"></div>-->
        <div  style="height: 100%;width: 100%;padding-top: 200px">
        <div id="w" class="easyui-window" title="登录系统" data-options="iconCls:'icon-save',modal:true,closable:false,draggable:false,resizable:false,shadow:true,minimizable:true,maximizable:false,collapsible:false" style="width:600px;height:400px;background: #B3DFDA;">
        <center><h2 style="margin-top:80px">蛋糕商城</h2>
            <table style="padding-top: 20px"><tr><td>用户名：</td><td><input type="text" class="easyui-textbox" id="userName" name="userName"></input></td></tr>
                <tr><td>密码：</td><td><input type="password" class="easyui-textbox" id="password" name="password"></input></td></tr>
                <tr><td colspan="2" style="text-align: center">
                    <input class="easyui-button" type="submit" id="submitBtn" name="submitBtn" value="登录" onclick="login()" />
                    <input class="easyui-button" type="reset" id="resetBtn" name="resetBtn" value="取消" />
                </td>
                </tr>
                <tr>
                        <td colspan="2" style="text-align: left"><a href="register.html">注册</a></td>
                </tr>
            </table>
            </center>
            </div>
            </div>
        </div>
    
    </body>
<script type="text/javascript">
$(function(){
    $("#userName").textbox("setValue","admin");
    $("#password").textbox("setValue","admin");
    $("#w").window();
});

function login(){
    var userName = $("#userName").val();
    var password = hex_sha1($("#password").val());
    $.ajax({
        type: "post",
        url: "../loginController/loginUser",
        data: JSON.stringify( {
            userName:userName,
            password:password
        }),
        dataType: 'json',
        contentType:"application/json;charset=UTF-8",
        success: function(data, textStatus) {
            if (data.success) {
                //var token = data.token;
                //window.localStorage.setItem("mytoken",token);
                window.location="../pages/index.html";
            }else{
                $.messager.alert("错误","登录失败！","error");
            }
        },
        complete : function(XMLHttpRequest, textStatus) {
        },
        error : function(XMLHttpRequest,textStatus,errorThrown) {
            //alert("Error:"+textStatus);
            //alert(errorThrown.toString());
            $.messager.alert("错误","登录错误！","error");
        }
    });
}

</script>
</html>
